<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title></title>
 <#include "/header.ftl">
    <style scoped>
        .stuInfo{
            width: 800px;
            border-width: 10px;
            border-spacing: 0;
            border-color: lightgray;
        }
        .stuInfo tr{
            width: 100px;
            height: 60px;
            text-align: center;
        }
        .stuInfoDiv{
            text-align: center;
            width: 800px;
            height: 600px;
            margin: 100px auto;
        }


    </style>
</head>
<body>
<div id="app">
    <h1>个人信息</h1>
    <div class="stuInfoDiv">
        <table class='stuInfo'  border="1">
            <tr>
                <td>学号</td>
                <td>{{studentInfo.studentId}}</td>
                <td>姓名</td>
                <td>{{studentInfo.studentName}}</td>
                <td rowspan="3" width="180" height="200">
                    <img :src="studentInfo.studentPhoto" width="180" height="200" />
                </td>
            </tr>
            <tr>
                <td>报考专业</td>
                <td>{{studentInfo.major.majorName}}</td>
                <td>性别</td>
                <td>{{studentInfo.studentSex}}</td>
            </tr>
            <tr>
                <td>出生年月</td>
                <td>{{studentInfo.studentBirth | dateFormat }}</td>
                <td>民族</td>
                <td>{{studentInfo.studentNation}}</td>
            </tr>
            <tr>
                <td>身份证号</td>
                <td colspan="4">{{studentInfo.studentIdcard}}</td>
            </tr>
            <tr>
                <td>学历</td>
                <td>{{studentInfo.studentEducation}}</td>
                <td>邮箱</td>
                <td colspan="2">{{studentInfo.studentEmail}}
                    <el-button type="primary"  size="small" @click.native="toUpdateEmail = true">修改</el-button>
                </td>
            </tr>
            <tr>
                <td>家庭住址</td>
                <td colspan="4">{{studentInfo.studentAddress}}</td>
            </tr>
            <tr>
                <td>毕业院校</td>
                <td>{{studentInfo.studentGraduate}}</td>
                <td>联系电话</td>
                <td colspan="2">{{studentInfo.studentPhone}}
                    <el-button type="primary"  size="small" @click.native="toUpdatePhone = true">修改</el-button>
                </td>
            </tr>
        </table>

        <!-- 修改邮箱地址 -->
        <el-dialog title="修改邮箱地址" :visible.sync="toUpdateEmail">
            <el-form :model="form">
                <el-form-item label="请输入邮箱：" :label-width="formLabelWidth">
                    <el-input v-model="form.newEmail" auto-complete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="toUpdateEmail = false">取 消</el-button>
                <el-button type="primary" @click.native="updateEmail">确 定</el-button>
            </div>
        </el-dialog>
        <!-- 修改联系方式弹出框 -->
        <el-dialog title="修改联系方式" :visible.sync="toUpdatePhone">
            <el-form :model="form">
                <el-form-item label="请输入联系电话：" :label-width="formLabelWidth">
                    <el-input v-model="form.newPhone" auto-complete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="toUpdatePhone = false">取 消</el-button>
                <el-button type="primary" @click.native="updatePhone">确 定</el-button>
            </div>
        </el-dialog>

    </div>

</div>
<#include "/footer.ftl">
<script>
    let _this=new Vue({
        el:'#app',
        data:{
            studentInfo:{
                major:''
            },
            toUpdateEmail: false,
            toUpdatePhone: false,
            form: {
                newEmail:'',
                newPhone:''
            },
            formLabelWidth: '140px',
        },
        created:function () {
            this.getStuMsg();
        },
        filters: {
            /*日期格式化*/
            dateFormat: function (val) {
                //console.log(date);
                let date = new Date(val);
                return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            }
        },
        methods: {

            getStuMsg:function(){
                $.ajax({
                    type:'post',
                    url:'api/student/studentSelfInfo',
                    data:{},
                    dataType:'json',
                    success:function (res) {
                        _this.studentInfo = res.resData;
                    },
                    error : function(error) {
                        console.log('接口不通' + error);
                    }
                })
            },
            update(){
                $.ajax({
                    type:'post',
                    url:'/api/student/updateStudentInfo',
                    data:{
                        newEmail: this.form.newEmail,
                        newPhone: this.form.newPhone
                    },
                    dataType:'json',
                    success:function (res) {
                        if(res.status == 200){
                            _this.$message({
                                showClose: true,
                                message: '修改成功，请查看',
                                type: 'success'
                            });
                            _this.getStuMsg();
                        }else{
                            _this.$message({
                                showClose: true,
                                message: res.message,
                                type: 'error'
                            });
                        }
                    },
                    error : function(error) {
                        console.log('接口不通' + error);
                    }
                })
            },
            updateEmail:function(){
                this.toUpdateEmail = false;
                this.update();
            },
            updatePhone:function() {
                this.toUpdatePhone = false;
                this.update();
            }

        }
    })
</script>

</body>
</html>
